﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PracticeCentre.Modeles;
using PracticeCentre.Common;
using PracticeCentre.Business;
using PracticeCentre.Mvc.Helper;
using PracticeCentre.Mvc.ViewModels;
using PracticeCentre.Mvc.Configs.Models;

namespace PracticeCentre.Mvc.Controllers
{
    public class InterviewController : Controller
    {
        private JsonResult result = new JsonResult();
        // GET: Interview
        public ActionResult Interview()
        {
            return View();
        }
        [HttpPost]
        //提交
        public ActionResult Interview(PageViewModel model)
        {
            string json;
            PageModel<InterModel> intermodel = ModelesMapping.Mapping<PageModel<InterModel>, PageViewModel>(model);
            intermodel = Business.Interviews.List(intermodel);
            if (intermodel != null)
            {
                json = JsonTool.JsonSerializer(intermodel);
                result = DataHelper.GetResult(ExecuteState.Succeed, "", json);
            }
            else
            {
                result = DataHelper.GetResult(ExecuteState.Succeed, "", "");
            }
            return result;
        }
        public ActionResult Insert()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Insert(InterViewModel model)
        {
            InterModel intermodel = ModelesMapping.Mapping<InterModel, InterViewModel>(model);
            if (Interviews.Insert(intermodel))
            {
                result = DataHelper.GetResult(ExecuteState.Succeed, "添加成功", "");
            }
            else
            {
                result = DataHelper.GetResult(ExecuteState.Succeed, "添加失败", "");
            }
            return result;
        }
    }
}